<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var MacroCommand = function(){
        return {
            commandsList: [],
            add: function( command ){
                this.commandsList.push( command );
            },
            execute: function(){
                for ( var i = 0, command; command = this.commandsList[ i++ ]; ){
                    command.execute();
                }
            }
        }
    };
    var openTvCommand = {
        execute: function(){
            console.log( '打开电视' );
        },
        add: function(){
            throw new Error( '叶对象不能添加子节点' );
        }
    };
    var macroCommand = MacroCommand();
    macroCommand.add( openTvCommand );
    openTvCommand.add( macroCommand )

</script>

</body>
</html>